package org.zwd.computePrice.action;

import java.util.ArrayList;
import java.util.List;

import org.zwd.computePrice.domain.Crab;
import org.zwd.computePrice.domain.CrabPrice;
import org.zwd.computePrice.service.CrabService;
import org.zwd.computePrice.service.TempService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class TempAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private CrabService crabService = new CrabService();
	private TempService tempService = new TempService();
	
	private String name;
	private int userid;
	private int isOrder;
	private int malecrabids[];
	private int femalecrabids[];
	private double malemounts[];
	private double femalemounts[];
	private double malecrabPrice[];
	private double femalecrabPrice[];
	private String maledescribes[];
	private String femaledescribes[];
	
	private int id;
	
	public String create() throws Exception{
		List<Crab> crabList = new ArrayList<Crab>();
		if(malecrabids !=null && malecrabids.length>0){
			for(int i = 0; i<malecrabids.length;i++){
				Crab crab = crabService.findCrabById(malecrabids[i]);
				CrabPrice crabPrice = new CrabPrice();
				crabPrice.setPrice(malecrabPrice[i]);
				crab.setCrabPrice(crabPrice);
				crab.setNote(maledescribes[i]);
				crab.setNumber(malemounts[i]);
				crabList.add(crab);
			}
		}
		
		if(femalecrabids !=null && femalecrabids.length>0){
			for(int i = 0; i<femalecrabids.length;i++){
				Crab crab = crabService.findCrabById(femalecrabids[i]);
				CrabPrice crabPrice = new CrabPrice();
				crabPrice.setPrice(femalecrabPrice[i]);
				crab.setCrabPrice(crabPrice);
				crab.setNote(femaledescribes[i]);
				crab.setNumber(femalemounts[i]);
				crabList.add(crab);
			}
		}
		
		tempService.createTemp(crabList, name, userid, isOrder);
		ActionContext.getContext().put("isOrder", isOrder);
		return "create";
	}
	
	public String show() throws Exception{
		ActionContext.getContext().put("id", id);
		ActionContext.getContext().put("isOrder", isOrder);
		return "show";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getUserid() {
		return userid;
	}

	public void setUserid(int userid) {
		this.userid = userid;
	}

	public int getIsOrder() {
		return isOrder;
	}

	public void setIsOrder(int isOrder) {
		this.isOrder = isOrder;
	}

	public int[] getMalecrabids() {
		return malecrabids;
	}

	public void setMalecrabids(int[] malecrabids) {
		this.malecrabids = malecrabids;
	}

	public int[] getFemalecrabids() {
		return femalecrabids;
	}

	public void setFemalecrabids(int[] femalecrabids) {
		this.femalecrabids = femalecrabids;
	}

	public double[] getMalemounts() {
		return malemounts;
	}

	public void setMalemounts(double[] malemounts) {
		this.malemounts = malemounts;
	}

	public double[] getFemalemounts() {
		return femalemounts;
	}

	public void setFemalemounts(double[] femalemounts) {
		this.femalemounts = femalemounts;
	}

	public double[] getMalecrabPrice() {
		return malecrabPrice;
	}

	public void setMalecrabPrice(double[] malecrabPrice) {
		this.malecrabPrice = malecrabPrice;
	}

	public double[] getFemalecrabPrice() {
		return femalecrabPrice;
	}

	public void setFemalecrabPrice(double[] femalecrabPrice) {
		this.femalecrabPrice = femalecrabPrice;
	}

	public String[] getMaledescribes() {
		return maledescribes;
	}

	public void setMaledescribes(String[] maledescribes) {
		this.maledescribes = maledescribes;
	}

	public String[] getFemaledescribes() {
		return femaledescribes;
	}

	public void setFemaledescribes(String[] femaledescribes) {
		this.femaledescribes = femaledescribes;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
}
